package com.rd.student.dashuju.sunwenzhuo.Test2;

import java.util.TreeSet;

public class Test6 {
    public static void main(String[] args) {

        Student s1 = new Student("liusan", 20, 90);
        Student s2 = new Student("lisi", 22, 90);
        Student s3 = new Student("wangwu", 20, 99);
        Student s4 = new Student("sunliu", 22, 100);

        TreeSet<Student> ts = new TreeSet<Student>();
        ts.add(s1);
        ts.add(s2);
        ts.add(s3);
        ts.add(s4);

        for (Student s : ts) {
            System.out.println(s.getName() + "," + s.getAge() + "岁," + s.getScore() + "分");
        }

       /* Collections.sort(list, new Comparator<Object>() {
            @Override
            public int compare(Object o1, Object o2) {
                Student student1 = (Student) o1;
                Student student2 = (Student) o2;
                if (student1.getScore() < student2.getScore()) {
                    return 1;
                } else if (student1.getScore() > student2.getScore()) {
                    return -1;
                }
                return 0;
            }
        });

        System.out.println(list);

        LinkedList list1 = new LinkedList();
        list1.add(list);

        System.out.println(list1);
        System.out.println("------------------------------");

        Collections.sort(list1, new Comparator<Object>() {
            @Override
            public int compare(Object o1, Object o2) {
                Student s1 = (Student) o1;
                Student s2 = (Student) o2;
                if (s1.getAge() > s2.getAge()) {
                    return 1;
                } else if (s1.getAge() < s2.getAge()) {
                    return -1;
                }
                return 0;
            }
        });

        System.out.println(list1);
    }
*/
    }
}

class Student implements Comparable<Student> {

    private String name;
    private int age;
    private int score;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }

    public Student() {

    }

    public Student(String name, int age, int score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    @Override
    public int compareTo(Student s) {
        int num = s.score - this.score;

       int num2 = num == 0 ? this.age-s.age:num;
        return num2;
    }
}




